id 'historysubmit' on lower submit button for changing the access keys
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2
3 /* Page history
4 Split off from Article.php and Skin.php, 2003-12-22
5 */
6
7 class PageHistory {
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
10 var $linesonpage;
11 function PageHistory( $article ) {
12 $this->mArticle =& $article;
13 $this->mTitle =& $article->mTitle;
14 }
15
16 # This shares a lot of issues (and code) with Recent Changes
17
18 function history()
19 {
20 global $wgUser, $wgOut, $wgLang, $wgIsMySQL;
21
22 # If page hasn't changed, client can cache this
23
24 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
26 return;
27 }
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
30
31 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
36
37 if( $this->mTitle->getArticleID() == 0 ) {
38 $wgOut->addHTML( wfMsg( "nohistory" ) );
39 wfProfileOut( $fname );
40 return;
41 }
42
43 list( $limit, $offset ) = wfCheckLimits();
44
45 /* We have to draw the latest revision from 'cur' */
46 $rawlimit = $limit;
47 $rawoffset = $offset - 1;
48 if( 0 == $offset ) {
49 $rawlimit--;
50 $rawoffset = 0;
51 }
52 /* Check one extra row to see whether we need to show 'next' and diff links */
53 $limitplus = $rawlimit + 1;
54
55 $namespace = $this->mTitle->getNamespace();
56 $title = $this->mTitle->getText();
57 $use_index=$wgIsMySQL?"USE INDEX (name_title_timestamp)":"";
58 $sql = "SELECT old_id,old_user," .
59 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
60 "FROM old $use_index " .
61 "WHERE old_namespace={$namespace} AND " .
62 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
63 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
64 $res = wfQuery( $sql, DB_READ, $fname );
65
66 $revs = wfNumRows( $res );
67
68 if( $revs < $limitplus ) // the sql above tries to fetch one extra
69 $this->linesonpage = $revs;
70 else
71 $this->linesonpage = $revs - 1;
72
73 $atend = ($revs < $limitplus);
74
75 $this->mSkin = $wgUser->getSkin();
76 $numbar = wfViewPrevNext(
77 $offset, $limit,
78 $this->mTitle->getPrefixedText(),
79 "action=history", $atend );
80 $s = $numbar;
81 if($this->linesonpage > 0) {
82 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
83 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
84 $this->submitbuttonhtml1 = $submitpart1 . ' />';
85 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
86 }
87 $s .= $this->beginHistoryList();
88 $counter = 1;
89 if( $offset == 0 ){
90 $this->linesonpage++;
91 $s .= $this->historyLine(
92 $this->mArticle->getTimestamp(),
93 $this->mArticle->getUser(),
94 $this->mArticle->getUserText(), $namespace,
95 $title, 0, $this->mArticle->getComment(),
96 ( $this->mArticle->getMinorEdit() > 0 ),
97 $counter++
98 );
99 }
100 while ( $line = wfFetchObject( $res ) ) {
101 $s .= $this->historyLine(
102 $line->old_timestamp, $line->old_user,
103 $line->old_user_text, $namespace,
104 $title, $line->old_id,
105 $line->old_comment, ( $line->old_minor_edit > 0 ),
106 $counter++
107 );
108 }
109 $s .= $this->endHistoryList( !$atend );
110 $s .= $numbar;
111 $wgOut->addHTML( $s );
112 wfProfileOut( $fname );
113 }
114
115 function beginHistoryList()
116 {
117 global $wgTitle;
118 $this->lastdate = $this->lastline = "";
119 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>';
120 $s .="\n<form action=\"" . $wgTitle->escapeLocalURL( '-' ) . "\" method=\"get\">";
121 $s .= "<input type=\"hidden\" name=\"title\" value=\"".wfEscapeHTML($wgTitle->getPrefixedDbKey())."\"/>\n";
122 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
123 $s .= "" . "\n<ul id=\"pagehistory\" >";
124 return $s;
125 }
126
127 function endHistoryList( $skip = false )
128 {
129 $last = wfMsg( "last" );
130
131 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
132 $s .= "</ul>";
133 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2."\n":'';
134 $s .= "</form>\n";
135 return $s;
136 }
137
138 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
139 {
140 global $wgLang;
141
142 $artname = Title::makeName( $ns, $ttl );
143 $last = wfMsg( "last" );
144 $cur = wfMsg( "cur" );
145 $cr = wfMsg( "currentrev" );
146
147 if ( $oid && $this->lastline ) {
148 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
149 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
150 } else {
151 $ret = "";
152 }
153 $dt = $wgLang->timeanddate( $ts, true );
154
155 if ( $oid ) {
156 $q = "oldid={$oid}";
157 } else {
158 $q = "";
159 }
160 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
161
162 if ( 0 == $u ) {
163 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
164 $ut, "target=" . $ut );
165 } else {
166 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
167 Namespace::getUser() ) . ":{$ut}", $ut );
168 }
169
170 $s = "<li>";
171 if ( $oid ) {
172 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
173 "diff=0&oldid={$oid}" );
174 } else {
175 $curlink = $cur;
176 }
177 $arbitrary = "";
178 if( $this->linesonpage > 1) {
179 # XXX: move title texts to javascript
180 $checkmark = "";
181 if ( !$oid ) {
182 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
183 $checkmark = ' checked="checked"';
184 } else {
185 if( $counter == 2 ) $checkmark = ' checked="checked"';
186 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
187 $checkmark = '';
188 }
189 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
190 }
191 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
192 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
193
194
195 if ( "" != $c && "*" != $c ) {
196
197 $c = $this->mSkin->formatcomment($c);
198 $s .= " <em>(" . $c . ")</em>";
199 }
200 $s .= "</li>\n";
201
202 $this->lastline = $s;
203 return $ret;
204 }
205
206 }
207
208 ?>